<?php

namespace common\models;

use Yii;

/**
 * This is the model class for table "{{%coupon}}".
 *
 * @property int    $id
 * @property string $name         优惠券名称
 * @property string $amount       金额
 * @property string $denomination 面额
 * @property int    $count        数量，0为不限
 * @property int    $create_time  开始时间
 * @property int    $update_time
 */
class CouponModel extends \yii\db\ActiveRecord
{
    public function beforeSave($insert)
    {
        if (parent::beforeSave($insert)) {
            if ($insert) {
                $this->create_time = $this->update_time = time();
            } else {
                $this->update_time = time();
            }
            return true;
        }
        return false;
    }


    /**
     * @inheritdoc
     */
    public static function tableName()
    {
        return '{{%coupon}}';
    }

    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            [['amount', 'denomination'], 'number'],
            [['count', 'create_time', 'update_time'], 'integer'],
            [['name'], 'string', 'max' => 30],
        ];
    }

    /**
     * @inheritdoc
     */
    public function attributeLabels()
    {
        return [
            'id' => 'ID',
            'name' => '优惠券名称',
            'amount' => '金额',
            'denomination' => '面额',
            'count' => '数量',
            'create_time' => '创建时间',
        ];
    }
}
